package cn.oscar.controller;

import cn.oscar.service.VoucherService;
import commonUtils.entities.Restful;
import commonUtils.entities.Voucher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/vouchers")
public class VoucherController {

    @Autowired
    private VoucherService voucherService;

    /**
     * 查询全部优惠券
     * @return 返回所有优惠券结果
     */
    @GetMapping
    public Restful<List<Voucher>> selectAll(){
        return voucherService.selectAllVoucher();
    }

    /**
     * 添加优惠券
     * @param voucher 优惠券信息
     * @return 返回添加操作信息
     */
    @PostMapping
    public Restful<String> addVoucher(@RequestBody Voucher voucher){
        return voucherService.addVoucher(voucher);
    }

    /**
     * 后台修改优惠券信息
     * @param voucher 优惠券信息
     * @return 返回修改操作信息
     */
    @PutMapping
    public Restful<String> updateVoucher(@RequestBody Voucher voucher){
        return voucherService.updateVoucher(voucher);
    }

    /**
     * 后台删除优惠券信息
     * @param id 优惠券id
     * @return 返回删除操作结果
     */
    @DeleteMapping
    public Restful<String> deleteVoucherById(@RequestParam Long id){
        return voucherService.deleteVoucherById(id);
    }



}
